/***************************************************************************
 *   Copyright (C) 2007 by Ziman & Xloverin                                *
 *   ziman@centrum.sk, xloverin@gmail.com                                  *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#ifndef MAINFORM_H
#define MAINFORM_H

#include <QMainWindow>
#include <QIcon>
#include <QDateTime>
#include <QLabel>
#include <QTimer>
#include "terminal.h"
#include "ui_mainform.h"
#include "query.h"

class Core;

/*
Jednorazovo:
TODO postovy klient (mozno lokalne ukladanie inboxu)
TODO forma na zobrazovanie profilov http://talker.sk/index.php?page=users&user=Xloverin
	- tlacidla - Open Query, Poslat postu, Detekcia online/offline, Examine do okna (zalozkove okno)
TODO nejaky anchor framework - klikatelne nazvy roomiek a userov (a ine)
TODO logging
TODO timestampy
TODO okno na letun, .rev buffre, hangman, piskvorky
TODO detach tabu do osobitneho okna a spatne zaclenenie
TODO form na editovanie .set, profilu, descu .ex
TODO editor s farbickami, ktory generuje talkrove farebne kody (pravy klik na input line -> Input colour)
*/

class MainForm : public QMainWindow, private Ui::MainWindow
{
	Core *core;
	Terminal *m_mainTerminal;
	
	// Labely v statusbare
	QLabel *lTime, *lIdle, *lNick, *lStatus, *lLogin;

	/// Timer updatujuci casy v statusbare.
	QTimer *statusTimer;

	/**
	 * Prepne na terminal so zadanym indexom (cisluje sa od nuly, mainTerminal
	 * ma index 0). Ak terminal so zadanym indexom neexistuje, nestane sa nic.
	 */
	void switchToTerminal(int index);

	/**
	 * Otvori uzivatelom preddefinovane terminaly pri starte.
	 */
	void openDefaultTerminals();
	
	/// Upozorni usera na aktivitu v okne, na win32 blikanim na taskbare, pripadne inym sposobom.
	void hilightWindow();

	Q_OBJECT

public:
	MainForm(QWidget* parent = 0, Qt::WFlags fl = 0 );
	virtual ~MainForm();

	/// Vrati hlavny terminal.
	Terminal *mainTerminal();

	/// Prida terminal na koniec zaloziek;
	void addTerminal(Terminal *terminal, QString title);

	/// Nastavi ikonku pre terminal.
	void setTerminalIcon(Terminal *terminal, Query::HilightLevel level);

	/// Vrati ktory terminal je prave otvoreny (ktory tab je aktivny).
	Terminal *activeTerminal();

	/// Nastavi poziciu tabov.
	void setTabPosition(QTabWidget::TabPosition tabPos);
	
	/// Zvizualizuje rezim citania.
	void displayCharMode(bool charMode);

	/// Autologin/autopripojenie.
	void connectIfNecessary();
public slots:
	void updateStatusbar();

	void onAfk(bool afk);

protected:
	virtual void closeEvent(QCloseEvent *evt);

protected slots:

	virtual void on_tabWidget_currentChanged(QWidget *widget);

	virtual void on_actionQuit_triggered();
	virtual void on_actionNew_query_triggered();
	virtual void on_actionPreferences_triggered();
	virtual void on_actionConnect_triggered();
	virtual void on_actionDisconnect_triggered();
	virtual void on_actionClose_current_triggered();
	virtual void on_actionDetach_current_triggered();
	virtual void on_actionColored_text_editor_triggered();
	virtual void on_actionAbout_Spiral_triggered();

	virtual void on_actionMain_toggled(bool);
	virtual void on_actionQueries_toggled(bool);
	virtual void on_actionMisc_toggled(bool);
	virtual void on_actionCharacter_mode_toggled(bool);

	virtual void on_actionMain_terminal_triggered();
	virtual void on_actionTerminal_2_triggered();
	virtual void on_actionTerminal_3_triggered();
	virtual void on_actionTerminal_4_triggered();
	virtual void on_actionTerminal_5_triggered();
	virtual void on_actionTerminal_6_triggered();
	virtual void on_actionTerminal_7_triggered();
	virtual void on_actionTerminal_8_triggered();
	virtual void on_actionTerminal_9_triggered();
	virtual void on_actionTerminal_10_triggered();
	
	virtual void on_actionDisplay_Gossip_query_triggered();
	virtual void on_actionUpdate_nick_list_triggered();
	virtual void on_actionWrite_a_message_triggered();

	void onConnected();
	void onDisconnected();
	void onLogin(QString nick);
	void onCloseTab(Terminal *terminal);
	void onAttachTab();
};

#endif

